package com.bootdo.blog.dao;

import com.bootdo.blog.domain.SeedlingDO;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-07 10:38:32
 */
@Mapper
public interface SeedlingMapper {

	@Select("select `seed_id`, `varieties`, `source`, `count`, `breed_type`, `breed_way`, `out_time`, `is_out`, `storage_way` from tb_seedling where seed_id = #{id}")
	SeedlingDO get(Integer seedId);
	
	@Select("<script>" +
	"select * from tb_seedling " + 
			"<where>" + 
		  		  "<if test=\"seedId != null and seedId != ''\">"+ "and seed_id = #{seedId} " + "</if>" + 
		  		  "<if test=\"varieties != null and varieties != ''\">"+ "and varieties = #{varieties} " + "</if>" + 
		  		  "<if test=\"source != null and source != ''\">"+ "and source = #{source} " + "</if>" + 
		  		  "<if test=\"count != null and count != ''\">"+ "and count = #{count} " + "</if>" + 
		  		  "<if test=\"breedType != null and breedType != ''\">"+ "and breed_type = #{breedType} " + "</if>" + 
		  		  "<if test=\"breedWay != null and breedWay != ''\">"+ "and breed_way = #{breedWay} " + "</if>" + 
		  		  "<if test=\"outTime != null and outTime != ''\">"+ "and out_time = #{outTime} " + "</if>" + 
		  		  "<if test=\"isOut != null and isOut != ''\">"+ "and is_out = #{isOut} " + "</if>" + 
		  		  "<if test=\"storageWay != null and storageWay != ''\">"+ "and storage_way = #{storageWay} " + "</if>" + 
		  			"</where>"+ 
			" <choose>" + 
	            "<when test=\"sort != null and sort.trim() != ''\">" + 
	                "order by ${sort} ${order}" + 
	            "</when>" + 
				"<otherwise>" + 
	                "order by seed_id desc" + 
				"</otherwise>" + 
	        "</choose>"+
			"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+
			"</script>")
	List<SeedlingDO> list(Map<String, Object> map);
	
	@Select("<script>" +
	"select count(*) from tb_seedling " + 
			"<where>" + 
		  		  "<if test=\"seedId != null and seedId != ''\">"+ "and seed_id = #{seedId} " + "</if>" + 
		  		  "<if test=\"varieties != null and varieties != ''\">"+ "and varieties = #{varieties} " + "</if>" + 
		  		  "<if test=\"source != null and source != ''\">"+ "and source = #{source} " + "</if>" + 
		  		  "<if test=\"count != null and count != ''\">"+ "and count = #{count} " + "</if>" + 
		  		  "<if test=\"breedType != null and breedType != ''\">"+ "and breed_type = #{breedType} " + "</if>" + 
		  		  "<if test=\"breedWay != null and breedWay != ''\">"+ "and breed_way = #{breedWay} " + "</if>" + 
		  		  "<if test=\"outTime != null and outTime != ''\">"+ "and out_time = #{outTime} " + "</if>" + 
		  		  "<if test=\"isOut != null and isOut != ''\">"+ "and is_out = #{isOut} " + "</if>" + 
		  		  "<if test=\"storageWay != null and storageWay != ''\">"+ "and storage_way = #{storageWay} " + "</if>" + 
		  			"</where>"+ 
			"</script>")
	int count(Map<String, Object> map);
	
	@Insert("insert into tb_seedling (`varieties`, `source`, `count`, `breed_type`, `breed_way`, `out_time`, `is_out`, `storage_way`)"
	+ "values (#{varieties}, #{source}, #{count}, #{breedType}, #{breedWay}, #{outTime}, #{isOut}, #{storageWay})")
	int save(SeedlingDO seedling);
	
	@Update("<script>"+ 
			"update tb_seedling " + 
					"<set>" + 
		            "<if test=\"seedId != null\">`seed_id` = #{seedId}, </if>" + 
                    "<if test=\"varieties != null\">`varieties` = #{varieties}, </if>" + 
                    "<if test=\"source != null\">`source` = #{source}, </if>" + 
                    "<if test=\"count != null\">`count` = #{count}, </if>" + 
                    "<if test=\"breedType != null\">`breed_type` = #{breedType}, </if>" + 
                    "<if test=\"breedWay != null\">`breed_way` = #{breedWay}, </if>" + 
                    "<if test=\"outTime != null\">`out_time` = #{outTime}, </if>" + 
                    "<if test=\"isOut != null\">`is_out` = #{isOut}, </if>" + 
                    "<if test=\"storageWay != null\">`storage_way` = #{storageWay}, </if>" + 
          					"</set>" + 
					"where seed_id = #{seedId}"+
			"</script>")
	int update(SeedlingDO seedling);
	
	@Delete("delete from tb_seedling where seed_id =#{seedId}")
	int remove(Integer seed_id);
	
	@Delete("<script>"+ 
			"delete from tb_seedling where seed_id in " + 
					"<foreach item=\"seedId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + 
						"#{seedId}" + 
					"</foreach>"+
			"</script>")
	int batchRemove(Integer[] seedIds);
}
